package com.igeek.d0612.test2;

/**
 * @Author: zhiyu
 * @Date:16:32
 * @DESC:
 */
public class AccountSys {
    private String name;
    private Double balance;
    private Object lock = new Object();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getBalance() {
        return balance;
    }

    public void setBalance(Double balance) {
        this.balance = balance;
    }

    @Override
    public String toString() {
        return "AccountSys{" +
                "name='" + name + '\'' +
                ", balance=" + balance +
                '}';
    }
    public AccountLock withdraw(double money){
        synchronized (lock){
            while (true){
                if (money>this.balance){
                    System.out.println("余额不足"+this.toString());
                    break;
                }else {
                    this.setBalance(this.getBalance()-money);
                    System.out.println("取款成功"+this.toString());
                }
            }
        }
       return null;
    }
}
